﻿

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using DesigneSpaceExplorerVEGA;
using GeneticAlgorithm;
using OxyPlot.Series;
using PSatSimCom;
using SelectorVE;

namespace Tester
{
    internal class Program
    {
        private static Stopwatch stopwatch = new Stopwatch();
        private static void Main(string[] args)
        {
            var points = new List<ScatterPoint>
            {
               /* new ScatterPoint(1, 1),
                new ScatterPoint(2, 1),
                new ScatterPoint(3, 1),
                new ScatterPoint(1, 2),
                new ScatterPoint(2, 2),
                new ScatterPoint(3, 2),*/
                new ScatterPoint(3, 8),
                new ScatterPoint(4, 6),
                new ScatterPoint(5, 5),
                new ScatterPoint(6, 3),
                new ScatterPoint(8, 2),
                new ScatterPoint(11, 2),
                new ScatterPoint(13, 2),
                new ScatterPoint(16, 3),
                new ScatterPoint(14, 10),

            };

            var hv = new Hypervolume();
            hv.Input = points;
            hv.Compute();
            Console.WriteLine("hv: " + hv.Output);
        }

        private static void TestApp()
        {
            stopwatch.Start();
            var psatsim = new PSatSim();
            psatsim.ThreadCount = 4;
            var veSelector = new VectorEvaluator();
            var ga = new GeneticCycler(psatsim, veSelector);
            ga.PopulationSize = 4;
            ga.OnClicleDone += ga_OnClicleDone;
            ga.Initialize();
            ga.Step();

            stopwatch.Start();
            var psatsim2 = new PSatSim();
            psatsim.ThreadCount = 4;
            var veSelector2 = new VectorEvaluator();
            var ga2 = new GeneticCycler(psatsim2, veSelector2);
            ga2.PopulationSize = 20;
            ga2.OnClicleDone += ga_OnClicleDone;
            ga2.Initialize();
            ga2.Step();

            Console.Read();
        }

        static void ga_OnClicleDone(GeneticCycler sender, GeneticCyclerArgs e)
        {
            stopwatch.Stop();
            var generationSelected = e.SelectedPopulation;
            var generationMutated = e.MutatedPopulation;
            var generation = e.InitialPopulation;
            var generationSim = e.SimulatedPopulation;
            var parameters = PSatSim.ConfigurationParameters;

            foreach (var simulatedConfiguration in generationSim)
            {
                Console.WriteLine("{0} {1} {2} {3}", simulatedConfiguration.Name
                    , simulatedConfiguration.GetScore("ipc")
                    , simulatedConfiguration.GetScore("power")
                    , simulatedConfiguration.GetScore("energy"));
            }
            Console.WriteLine(stopwatch.ElapsedMilliseconds);
        }
    }
}